package models.users

import java.sql.Timestamp
import java.time.LocalDateTime

case class UserGroup(
                      id: Long = 0,
                      uid: Int,
                      gid: Long
                    )

case class Group(
                  id: Long = 0,
                  parentid: Long = 0,
                  pname: String = "",
                  company: Int, //# go-fast 部门所属的google_secret
                  nas_gid: Int = 0
                )

case class User(
                 id: Option[Int] = None, //
                 company: Int,
                 password: String = "nopassword", //
                 username: String = "", //  手机号码hash
                 position: Option[String] = None, //  职位信息
                 email: Option[String] = None, //  员工的电子邮箱
                 is_active: Boolean = false, //
                 userid: String = "", //  员工在当前企业内的唯一标识，也称staffId。可由企业在创建时指定，并代表一定含义比如工号，创建后不可修改
                 unionid: String = "", //  员工在当前开发者企业账号范围内的唯一标识，系统生成，固定值，不会改变
                 tel: Option[String] = None, //  分机号（仅限企业内部开发调用）
                 workPlace: Option[String] = None, //  办公地点
                 remark: Option[String] = None, //  备注
                 mobile: String = "", //  手机号码
                 orgEmail: Option[String] = None, //  员工的企业邮箱，如果员工已经开通了企业邮箱，接口会返回，否则不会返回
                 isLeaderInDepts: Option[String] = None, //  在对应的部门中是否为主管：Map结构的json字符串，key是部门的Id，value是人员在这个部门中是否为主管，true表示是，false表示不是
                 department: String = "", //  成员所属部门id列表
                 avatar: Option[String] = None, //  头像url
                 hiredDate: Timestamp = Timestamp.valueOf(LocalDateTime.now()), //  入职时间。Unix时间戳 （在OA后台通讯录中的员工基础信息中维护过入职时间才会返回)
                 jobnumber: Option[String] = None, //  员工工号
                 extattr: Option[String] = None, //  扩展属性，可以设置多种属性（但手机上最多只能显示10个扩展属性，具体显示哪些属性，请到OA管理后台->设置->通讯录信息设置和OA管理后台->设置->手机端显示信息设置
                 lastLoginDate: Option[Timestamp] = None,
                 is_admin: Boolean = false
               )

case class Account(
                    id: Option[Int] = None, //
                    password: String = "nopassword", //
                    username: String = "", //  手机号码hash
                    position: Option[String] = None, //  职位信息
                    permission: Int = 0, //
                    userid: String = "", //  员工在当前企业内的唯一标识，也称staffId。可由企业在创建时指定，并代表一定含义比如工号，创建后不可修改
                    unionid: String = "", //  员工在当前开发者企业账号范围内的唯一标识，系统生成，固定值，不会改变
                    mobile: String = "", //  手机号码
                    avatar: Option[String] = None, //  头像url
                    lastLoginDate: Option[Timestamp] = None,
                    //is_admin: Boolean = false,
                    //                    permission: Int = 0,
                    op_date: Timestamp = Timestamp.valueOf(LocalDateTime.now())
                  )

case class UserInfo(
                     id: Option[Int] = None, //
                     accountId: Int,
                     company: Int,
                     is_active: Int = 0,
                     username: String = "", //  手机号码hash
                     position: Option[String] = None, //  职位信息
                     email: Option[String] = None, //  员工的电子邮箱
                     userid: String = "", //  员工在当前企业内的唯一标识，也称staffId。可由企业在创建时指定，并代表一定含义比如工号，创建后不可修改
                     unionid: String = "", //  员工在当前开发者企业账号范围内的唯一标识，系统生成，固定值，不会改变
                     tel: Option[String] = None, //  分机号（仅限企业内部开发调用）
                     workPlace: Option[String] = None, //  办公地点
                     remark: Option[String] = None, //  备注
                     mobile: String = "", //  手机号码
                     orgEmail: Option[String] = None, //  员工的企业邮箱，如果员工已经开通了企业邮箱，接口会返回，否则不会返回
                     isLeaderInDepts: Option[String] = None, //  在对应的部门中是否为主管：Map结构的json字符串，key是部门的Id，value是人员在这个部门中是否为主管，true表示是，false表示不是
                     department: String = "", //  成员所属部门id列表
                     avatar: Option[String] = None, //  头像url
                     hiredDate: Timestamp = Timestamp.valueOf(LocalDateTime.now()), //  入职时间。Unix时间戳 （在OA后台通讯录中的员工基础信息中维护过入职时间才会返回)
                     jobnumber: Option[String] = None, //  员工工号
                     extattr: Option[String] = None, //  扩展属性，可以设置多种属性（但手机上最多只能显示10个扩展属性，具体显示哪些属性，请到OA管理后台->设置->通讯录信息设置和OA管理后台->设置->手机端显示信息设置
                     leaveDate: Option[Timestamp] = None, // 离职时间
                     op_date: Timestamp = Timestamp.valueOf(LocalDateTime.now())
                   )

case class NasGroup(
                     id: Option[Int] = None,
                     nas_id: Int = 0,
                     nas_name: String = "",
                     pname: String = "",
                     checked: Boolean = false
                   )

case class NasUser(
                    id: Int,
                    nas_id: Int = 0,
                    nas_name: String = "",
                    locked: Boolean = false,
                    group_id: Int = 35,
                    checked: Boolean = false
                  )

/**
 * INSERT into USERS_USERINFO (id,username,position,email,userid,unionid,tel,workPlace,remark,mobile,orgEmail,isLeaderInDepts,department,avatar,hiredDate,jobnumber,extattr)
 * SELECT id,username,position,email,userid,unionid,tel,workPlace,remark,mobile,orgEmail,isLeaderInDepts,department,avatar,hiredDate,jobnumber,extattr FROM USERS_USER;
 */
case class KingdeeDataCenter(
                              id: String, // = models.CharField(primary_key=True,max_length=20)
                              name: String, // = models.CharField(max_length=100)
                              test: Boolean = false, // = models.BooleanField
                            )
//case class KingdeeConfig(url: String, acctID: String, userName: String, password: String, lcid: Int = 2052)

case class KingdeeUser(
                        id: Long, // = models.IntegerField(primary_key=True)
                        acct_id: String, // = models.CharField(max_length=20)
                        base_user_id: Option[Int] = None, // = models.BigIntegerField(null=True,blank=True)
                        name: String, // = models.CharField(max_length=20)
                        mobile: String, // = models.CharField(max_length=20)
                        forbid_status: String, // = models.CharField(max_length=1)
                        disable_time: Option[Timestamp] = None, // = models.DateTimeField(null=True,blank=True)
                        fAppGroup: String, // = models.CharField(max_length=10)
                        status: Int = 0 // = models.SmallIntegerField(default=0)
                      )

/**
 *
 * @param id
 * @param base_user_id
 * @param name
 * @param mobile
 * @param status  0 => "禁用"; 1 => "待禁用"; 2 => "正常"; 3 => "离职"; 9 => "其他"; _ => "未知"
 * @param disable_time
 */
case class GyErpUser(
                      id: Long, // = models.IntegerField(primary_key=True)
                      base_user_id: Option[Int] = None, // = models.BigIntegerField(null=True,blank=True)
                      name: String, // = models.CharField(max_length=20)
                      mobile: String, // = models.CharField(max_length=20)
                      status: Int = 0, // = models.SmallIntegerField(default=0)
                      disable_time: Option[Timestamp] = None // = models.DateTimeField(null=True,blank=True)
                    )

object SystemUsersStatusName {
  val idName: Seq[(Int, String)] = Seq((0, "禁用"), (1, "待禁用"), (2, "正常"), (3, "离职"), (9, "其他"))

  private def status(id: Int) = id match {
    case 0 => "禁用"
    case 1 => "待禁用"
    case 2 => "正常"
    case 3 => "离职"
    case 9 => "其他"
    case _ => "未知"
  }

  def statusId(id: Int) = {
    val q = idName.filter(_._1 == id).map(f => f._2)
    if (q.isEmpty) "未知" else q.head
  }
}